package dblog.article.web;

import dblog.article.Article;
import dblog.article.dao.ArticleDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Component
public class ArticleController {

	@Autowired
	private ArticleDAO articleDAO;


	@RequestMapping("/articles/list")
	public ModelAndView listContacts(HttpServletRequest arg0, HttpServletResponse arg1) {
	    Map<String,List<Article>> map = new HashMap<String,List<Article>>();
		map.put("articles", articleDAO.getAllArticles());

		return new ModelAndView("list",map);
	}
}
